package com.wlc.oop.demo05;

/**
 * @author 王立朝 wanglichao@champion-credit.com
 * @description 测试
 * @date 2021-06-27 10:44
 */
public class Test {
    public static void main(String[] args) {
        Teacher teacher = new Teacher();
        Person teacher1 = new Teacher();
        Object teacher2 = new Teacher();
        // instanceof 左边的teacher  是 右边 类 Teacher 类的一个实例
        // instanceof 是用来测试  左边的对象是否是右边类的一个实例，返回一个不二类型的值
        System.out.println(teacher instanceof Teacher);
        System.out.println(teacher1 instanceof Teacher);
        System.out.println(teacher2 instanceof Object);
        System.out.println("=======");
        // 将Person 这个对象抢转换成 Teacher 对象，就可以使用子类中的方法了。
        Person person = new Teacher();
        ((Teacher) person).run();
        // 子类转换为父类
        Person person1 = new Teacher();
        System.out.println("person1");
        // 不能用子类的引用指向父类
        Teacher teacher3 = (Teacher) new Person();
        teacher3.run();

    }
}
